var gl_bedCost_vue_vm_list_html = $('#bedCost_vue_vm_list').html();
var bedCostArray = null;

$(function() {
	var option = $('#bedCost_cond_select option:selected');
	$('#userVipCard_vue_vm_list').html('');
	$('#bedCost_vue_vm_list').html('');
	
	houseTypeTypeClick();
	load_bedCost_select();
	load_bedCost_cond_select();
});

var bedCost = {
	bedCostId: '',
	houseTypeId: '',
	price: '',
	subsidization: '',
	subsidizationValue: '',
	consumptionWay: '',
	consDeductionWay: '',
	discount: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	consumptionType: 1
};

function load_bedCost_select() {
	if($('#bedCost_select').length==0) {return;}

	$('#bedCost_select').html('<option value="" selected></option>');

	findAll_basic(path+'/bedCost/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#bedCost_select').append('<option value="' + response.data[i].bedCostId
				+ '">' + response.data[i].bedCostName + '</option>');
		}
	});
}

function load_bedCost_cond_select() {
	if($('#bedCost_cond_select').length==0) {return;}

	$('#bedCost_cond_select').html('<option value="" selected></option>');

	findAll_basic(path+'/bedCost/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#bedCost_cond_select').append('<option value="' + response.data[i].bedCostId
				+ '">' + response.data[i].housrTypeName + ' ' + response.data[i].price + '元/月</option>');
		}
		
		bedCostArray = response.data;
		_addChangeListener("#bedCost_cond_select", function() {
			var option = $('#bedCost_cond_select option:selected');
			var bedCostId_select = $('#bedCost_cond_select').val();
			$('#bedCost_vue_vm_list').html(gl_bedCost_vue_vm_list_html);
			
			for(var i=0; i<bedCostArray.length; i++) {
				if(bedCostArray[i].bedCostId==bedCostId_select) {
					new Vue({
						el: '#bedCost_vue_vm_list',
						data: {
							todos: [bedCostArray[i]]
						}
					});
					
					if(view && view.data) {
						view.data.bedCostId = bedCostArray[i].bedCostId;
						view.data.bedCostPrice = bedCostArray[i].price;
						view.data.houseTypeId = bedCostArray[i].houseTypeId;
						view.data.houseTypeName = bedCostArray[i].housrTypeName;
						view.data.subsidization = bedCostArray[i].subsidization;
						view.data.subsidizationValue = bedCostArray[i].subsidizationValue;
						view.data.consumptionWay = bedCostArray[i].consumptionWay;
						view.data.discount = bedCostArray[i].discount;
						view.data.consDeductionWay = bedCostArray[i].consDeductionWay;
						view.data.consumptionType = 1;
					}
				}
			}
		});
	});
}

function houseTypeTypeClick() {
	var houseTypeType = $('input:radio[name="houseTypeType"]:checked').val();
	if(houseTypeType=='vipCard') {
		$('#bedCost_cond_select').attr("disabled", true);
		$('#userVipCard_vue_vm_list').show();
		$('#bedCost_vue_vm_list').hide();
		$('#btn_userVipCard_search').show();
	}else if(houseTypeType=='ordinary') {
		$('#bedCost_cond_select').attr("disabled", false);
		$('#userVipCard_vue_vm_list').hide();
		$('#bedCost_vue_vm_list').show();
		$('#btn_userVipCard_search').hide();
	}
}